from django.db import models


class MonitorHttp(models.Model):
    title = models.CharField(max_length=120, verbose_name="监控名称")
    url = models.TextField(verbose_name='监控url', help_text='同一组服务器多个url监控换行即可')
    monitor_type = models.BooleanField(default=True, verbose_name='请求方式')
    monitor_ip = models.TextField(verbose_name='ip列表')
    mail_status = models.BooleanField(verbose_name="是否邮件报警", default=True)
    mail = models.TextField(verbose_name='邮件联系人', help_text='多个邮件联系人换行即可')
    weixin_status = models.BooleanField(verbose_name='是否微信报警', default=True)
    weixin = models.TextField(verbose_name='微信联系人', help_text='多个联系人换行即可')
    payload = models.TextField(verbose_name='post数据', null=True, blank=True, help_text='POST提交数据,需json格式')
    status = models.BooleanField(verbose_name='状态', default=True)
    result_code = models.BooleanField(verbose_name='header/code', default=True,
                                      help_text='默认监控http status,如果选择为返回值,则监控返回数据retCode是否为200')
    createtime = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = "http监控"
        verbose_name_plural = verbose_name


class MonitorHttpLog(models.Model):
    monitorId = models.CharField(max_length=120, verbose_name="监控ID")
    monitor_title = models.CharField(max_length=120, verbose_name="监控名称")
    content = models.TextField(verbose_name="日志内容", null=True, blank=True)
    code = models.IntegerField(verbose_name='状态码')
    job_id = models.CharField(max_length=32, verbose_name='任务id')
    status = models.BooleanField(verbose_name='状态', default=True)
    createtime = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.monitor_title

    class Meta:
        verbose_name = "http监控日志"
        verbose_name_plural = verbose_name


class MonitorMySql(models.Model):
    name = models.CharField(max_length=120, verbose_name="监控名称")
    monitor_ip = models.TextField(verbose_name='ip列表')
    monitor_user = models.CharField(verbose_name='用户名', max_length=32, help_text='监控帐号')
    monitor_pass = models.CharField(verbose_name='用户名', max_length=128, help_text='监控密码')
    monitor_port = models.IntegerField(verbose_name='端口', help_text='mysql端口')
    mail = models.TextField(verbose_name='邮件', help_text='多个邮件联系人换行即可')
    weixin = models.TextField(verbose_name='微信', help_text='多个联系人换行即可')
    slave = models.BooleanField(verbose_name='主从', default=True)
    status = models.BooleanField(verbose_name='状态', default=True)
    createtime = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = "mysql监控"
        verbose_name_plural = verbose_name
